<?php
/**
 *
 * User: 梁晓伟  lxw11109@gmail.com
 * Date: 2017-11-05
 * Time: 16:37
 */

namespace App\Http\Controllers\Api\V1\Manager\Supplier;


use App\Http\Controllers\Controller;
use App\Models\Brand;
use App\Models\Good;
use App\Models\GoodsOneType;
use App\Models\GoodsTwoType;
use App\Models\Order;
use App\Models\OrderDetail;
use App\Models\Supplier;
use App\Models\UserHome;
use App\Models\UserStatistics;
use App\Models\VipLog;
use DateTime;
use Illuminate\Http\Request;
use Maatwebsite\Excel\Facades\Excel;

class BrandController extends Controller
{
    public function index(Request $request)
    {
        $name = $request->name;
        $pageSize = $request->pageSize;
        $sql = Brand::select();
        if (isset($name)) {
            $sql->where('name', 'like', "%$name%");
        }
        $brandList = $sql->orderByDesc('createtime')
            ->paginate($pageSize)
            ->toArray();
        $data['brandList'] = $brandList['data'];
        foreach ($data['brandList'] as $key => $value) {
            if (isset($value['createtime'])) {
                $data['brandList'][$key]['createtime'] = date("Y-m-d H:i:s", $value['createtime']);
            }
        }
        $data['totalNum'] = $brandList['total'];
        return $this->apiResponse($data);

    }
}